<!DOCTYPE html>
<html>
    <head>
        <?php
        include 'browser_detect.php';
        if (isMobile()) {
            $leftURL = "/gsearch";
            $rightURL = "/bmsearch";
            ?>

            <meta name="HandheldFriendly" content="true" />
            <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no" />
            <?php
        } else {
            $leftURL = "/gsearch";
            $rightURL = "/bsearch";
        }

        if ($_GET["left_choice"] != NULL) {
            $leftURL = $_GET["left_choice"];
        } else if ($_COOKIE['left_choice'] != NULL) {
            $leftURL = $_COOKIE['left_choice'];
        }

        if ($_GET["right_choice"] != NULL) {
            $rightURL = $_GET["right_choice"];
        } else if ($_COOKIE['right_choice'] != NULL) {
            $rightURL = $_COOKIE['right_choice'];
        }
        ?>


        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
        <meta name="title" content="One Search" />
        <meta name="keywords" content='<?php echo $_GET["q"]; ?>' />
        <meta name="description" content=" The best search tool. Search Once, you can get results from both google and bing side by side with 
              the same item highlighted.Google vs Bing  <?php echo $_GET["q"]; ?>  " />

        <link rel="stylesheet" type="text/css" href="css/wordlist.css"/> 
        <link rel="stylesheet" type="text/css" href="css/button.css"/> 

        <script src="//www.google.com/jsapi" type="text/javascript"></script>
        <script type="text/javascript">
            google.load('search', '1');
            function inputFocus() {
                document.getElementById('searchText').style['background'] = '';
            }

            function inputBlur() {
                var queryInput = document.getElementById('searchText');
                if (!queryInput.value) {
                    queryInput.style['background'] =
                        'white url(http://www.google.com/coop/images/'
                        + 'google_custom_search_watermark.gif) no-repeat 0% 50%';
                }
            }

            function init() {
                //var cx = '011152833664020937705:ytiupixbdcs';
                google.search.CustomSearchControl.attachAutoCompletion(
                '006146382722072746140:rc7_dtmydr0',
                //'011152833664020937705:ytiupixbdcs',
                document.getElementById('searchText'),
                'searchForm');
                inputBlur();
            }

            function submitQuery() {
                window.location = '/html/two_page_search_results.html?q='
                    + encodeURIComponent(
                document.getElementById('searchText').value);
                return false;
            }
            google.setOnLoadCallback(init);
        </script>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

        <script type="text/javascript" src="js/jquery.cookie.js"></script>

        <script>
             
            $(document).ready(function() {
                
                $("#left_frame").width($(document).width()/2-40);
                $("#right_frame").width($(document).width()/2-40);
             
                $("#hide_left").attr("checked",  $.cookie("hideItem") == "left");
                $("#hide_right").attr("checked",  $.cookie("hideItem") == "right");

                $("#hide_left").bind("click", function() {
                   //alert(1);    
                    if ($(this).attr('checked')) {
                        $("#hide_right").attr('checked', false);
                        $.cookie("hideItem", "left", { expires:365});
                    } else {
                        $.cookie("hideItem", "");
                    }
                    itemManage();
                });
                $("#hide_right").bind("click", function() {
                    if ($(this).attr('checked')) {
                        $("#hide_right").attr('checked', false);
                        $.cookie("hideItem", "right", { expires:365});
                    }  else {
                        $.cookie("hideItem", "");
                    }
                    itemManage();
                });
        
                
                
                
                $("select").change(function(ev) {
                    var newVal = $(this).val();
                    if ($("#left_choice").val() == $("#right_choice").val())
                    {
                        $(this).val($.data(this, 'val'));
                        return ;
                       
                    }
                    $.data(this, 'val', newVal);
                    $.cookie("left_choice", $("#left_choice").val(),  { expires:365})
                    $.cookie("right_choice", $("#right_choice").val(),  { expires:365})
                });
                
                if ($.cookie("left_choice") != null && $.cookie("right_choice") !=null)
                {
                    $("#left_choice").val($.cookie("left_choice"));
                    $("#right_choice").val($.cookie("right_choice"));
                }

            });
    

            $(window).resize(function() {
                $("#left_frame").width($(document).width()/2-20);
                $("#right_frame").width($(document).width()/2-20);
            });
        </script>

    </head>

    <body>

        <div class="topmenu" style="background-color: black;margin:0;padding:0;margin-top:-10px;margin-left:-10px">
            <a title="One Query Gets both Results from Bing and Google!" style="color:orange" href="/onesearch"> OneSearch </a>
            <a href="/wordlist"> Wordlist </a> 
            <a title="A large collection of test papers of most states of U.S. "
               href="/wordlist/gdoc/list.jsp" target='googledoc'> StateTestCollection </a>                        

            <!-- <a href="/wordlist_chinese"> ChineseWordlist </a>    -->
            <a href="/youaudio"> YouAudio </a>  

        </div>   

        <?php if (!isMobile()) { ?>
            <h2 align="center"" > One Search Gets Both Results from <span style="color: brown" > Google </span> and <span style="color:green">  Bing </span> </h1>
        <?php } else { ?>

            <h3 align="center"> One Search </h3>

            <?php
        }
        $terms = array("irs", "Samsung Tablet", "Amazon Stores", "Xbox", "Kindle", "Playstation", "iPhone", "iPad", "Wii", "iPad", "Nook", "Windows Phone", "Macbook Pro");
        $q = $_GET["q"];
        if ($q == null)
            $q = $terms[rand(0, count($terms) - 1)];
        ?>
        <h2 align="center">
            <?php if (isMobile()) { ?>

                <script type="text/javascript"><!--
                    google_ad_client = "ca-pub-1830488441040930";
                    /* mobile-onesearch */
                    google_ad_slot = "2290733974";
                    google_ad_width = 320;
                    google_ad_height = 50;
                    //-->
                </script>
                <script type="text/javascript"
                        src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                </script>
            <?php } else { ?>
                <table align="center"><tr><td>
                        </td><td>
                            <script type="text/javascript"><!--
                                google_ad_client = "ca-pub-1830488441040930";
                                /* wordlist */
                                google_ad_slot = "4413544198";
                                google_ad_width = 728;
                                google_ad_height = 90;
                                //-->
                            </script>
                            <script type="text/javascript"
                                    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                            </script></td></tr></table>
            <?php } ?>
        </h2>
        <h3 align="center"> 
            <form id="searchForm" method="GET">

                <input autocomplete="off" id="searchText" name=q type="text" value='<?php echo $q; ?>'
                       size= '<?php echo isMobile() ? "20" : "60"; ?>' maxlength=250/>


                <input type="button" value="X" onclick="$('#searchText').val('') "  style="margin-left: -40px"/>
                <input type="submit" value="Search" /> 
                <?php if (!isMobile()) { ?>
                    <a class="sp" onclick="window.external.AddSearchProvider('http://www.elookinto.com/onesearch/search.xml');" 
                       href="#">Add to browser search</a> <?php } ?>
                <br/>
                <span style="margin-left: 50px;float: left">
                    <select id="left_choice" name="left_choice">
                        <option value='/gsearch'> Google</option>
                        <option value='/bsearch'> Bing</option>
                        <option value="/ysearch"> Yahoo</option>
                        <option value="/asearch"> Ask</option>
                    </select>
                    <select id="right_choice" name="right_choice">
                        <option value="/bsearch"> Bing</option>
                        <option value="/gsearch"> Google </option>
                        <option value="/ysearch"> Yahoo</option>
                        <option value="/asearch"> Ask</option>
                    </select>
                </span>
                <input id="prev" type="submit" style="display:none"  value="Prev"/>
                <input id="next" type="submit" style="display:none"  value="Next"/> 

                <span style="font-weight:normal;font-size:small; margin-left:40px"> Hide the same items in Left Panel:
                    <input type="checkbox" id="hide_left" /> &nbsp; &nbsp; &nbsp; 
                Right Panel: <input type="checkbox" id="hide_right" /> </span>
                <input id="leftq" name=leftq type="hidden"  value=""/>
                <input id="rightq" name=rightq type="hidden"  value=""/>
            </form> </h3>



        <?php
        $leftq = $_GET["leftq"];
        $rightq = $_GET["rightq"];
        if ($leftq == null || strlen($leftq) == 0)
            $leftq = "q=" . $q;
        else
            $leftq = substr($leftq, 8);
        if ($rightq == null || strlen($rightq) == 0)
            $rightq = "q=" . $q;
        else
            $rightq = substr($rightq, 8);
//echo $leftq."====".$rightq."<br/>";
        ?>  
        <iframe width=800 height=2000 src='<?php echo$leftURL . "?" . $leftq; ?>'  id='left_frame'> </iframe>
        <iframe width=800 height=2000 src='<?php echo$rightURL . "?" . $rightq; ?>'  id='right_frame'> </iframe>

        <script>

            
            function getDoc(aid)
            {
                var x=document.getElementById(aid);
                var y=(x.contentWindow || x.contentDocument);
                if (y.document)y=y.document;
                return y; 
            }
   
       

            var delay = 1000;
            var max = 0;
            var handleLeft, handleRight;
            function clearTimer(force)
            {
                //alert(max);
                if (max < 7 && !force) return;
                window.clearInterval(handleLeft);
                window.clearInterval(handleRight);
            }

            
            function itemManage() {

                var color = ["red", "orange","IndianRed", "brown", "Olive", "Magenta", "Maroon", "Coral", "DarkRed", "DarkSalmon"];
                a1 = $('#right_frame').contents().find('a').toArray();
                a2 = $('#left_frame').contents().find('a').toArray();
                for (i=0; i<a1.length; i++)  $(a1[i]).attr("target", "_blank");
                for (j=0; j<a2.length; j++)  $(a2[j]).attr("target", "_blank");
                t=0;
                for (i=0; i<a1.length; i++){
                    for (j=0; j<a2.length; j++)
                    {
                        if ( $(a1[i]).attr("href") == $(a2[j]).attr("href") ){
                                     
                            $(a1[i]).css("color", color[t%10]);
                            $(a2[j]).css("color", color[t%10]);
                            //$(a2[j]).css("display", "none");
                            if ($("#hide_left").is(":checked"))  {
                                $(a2[j]).closest("li").css("display", "none");
                                 $(a2[j]).closest("div[class=tsrc_tled]").css("display", "none");
                              }
                            else {
                                $(a2[j]).closest("li").css("display", "block");
                                $(a2[j]).closest("div[class=tsrc_tled]").css("display", "block");
                              }

                            if ($("#hide_right").is(":checked")) {
                                $(a1[i]).closest("li").css("display", "none");
                                $(a1[i]).closest("div[class=tsrc_tled]").css("display", "none");
                              }
                            else {
                                 $(a1[i]).closest("li").css("display", "block");
                                  $(a1[i]).closest("div[class=tsrc_tled]").css("display", "block");
                            }
             
                            t++;    
                        };
                    }
                }
            }

             function   fixLatencyLoading()
              {
                    max++;
                   clearTimer(false);
                   gsearch = $('#left_frame').contents().find('a:contains("Next")');
                   bsearch =  $('#right_frame').contents().find('a:contains("Next")');
                   if (gsearch.size()>0 && bsearch.size()>0)
                    { $("#next").show();
                        //window.clearInterval(handleLeft);
                        //alert("next");
                        clearTimer(true);
                        itemManage();
                    }

                    ggsearch = $('#left_frame').contents().find('a:contains("Prev")');
                    bbsearch =  $('#right_frame').contents().find('a:contains("Prev")');
                    //alert(bbsearch.size());
                   // alert(ggsearch.size());
                    //if (bbsearch.size()>0) alert(bbsearch.attr('href'))
                    if (ggsearch.size()>0 || bbsearch.size()>0) {
                        $("#prev").show();
                        clearTimer(true);
                        itemManage();
                    }
               }

            $('#right_frame').ready(function(){
                                       
                handleRight = window.setInterval(function() {
                   
                 fixLatencyLoading();
                         
                }, delay);
               
            });

             function fixNav(navButtonTxt, frameId)
              {
                   navLink = $(frameId).contents().find('a:contains("' + navButtonTxt +'")');
                   if (navLink.size()>0) {
                    var nextHref = navLink.attr("href");
                        nextHref =  nextHref.replace(/\/search;.*\?/, "/search?"); //yahoo
                        nextHref =  nextHref.replace(/http:\/\/www\.ask\.com\/web/, "/search"); //ask
                        //alert(nextHref);
                        if (frameId.indexOf("left")>=0)
                         $("#leftq").val(nextHref);
                        if (frameId.indexOf("right")>=0)
                         $("#rightq").val(nextHref);

                  }
              }

            $('#left_frame').ready(function(){
             
                 handleLeft = window.setInterval(function() {

                 fixLatencyLoading();

                }, delay);

                
                 
                $("#next").bind("click", function() {
                  //alert(1);
                  fixNav("Next", "#left_frame");
                  fixNav("Next", "#right_frame");                
                });
                      
                $("#prev").bind("click", function() {
                   fixNav("Prev", "#left_frame");
                   fixNav("Prev", "#right_frame");
                  
                });
                 itemManage();
            });

        </script>


        <div id=adrite style="display:none">


        </div>

        <div id=g>
        </div>


        <h3 align="center"> Copyright (c) 2012, ELOOKINTO. </h3>

</body>
</html>
